package com.huilian.iotbox.admin.wap.controller;

import com.huilian.iotbox.admin.wap.service.PushConfigItemService;
import com.huilian.iotbox.admin.wap.service.PushConfigService;
import com.huilian.iotbox.admin.wap.service.UserService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.PushConfigDto;
import com.huilian.iotbox.data.dto.PushConfigItemDto;
import com.huilian.iotbox.data.enums.RoleEnum;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author LinYinDong
 * @date 2024/1/9 15:28
 */
@RestController
@RequestMapping("/api/pushConfigItem")
public class PushConfigItemController {
    @Autowired
    private PushConfigItemService pushConfigItemService;
    @Autowired
    private UserService userService;

    /**
     * 编辑消息推送的开关
     * */
    @PostMapping("/editOnePushConfigItem")
    public ServerResponse editOnePushConfigItem(HttpServletRequest request, @RequestBody PushConfigItemDto pushConfigItemDto) {
        UserInfo userInfo = userService.getLoginUserInfo(request);
        if(ObjectUtils.isEmpty(userInfo)){
            return ServerResponse.createByErrorMessage("获取商户信息失败");
        }
        pushConfigItemDto.setUserId(userInfo.getId());
        return pushConfigItemService.editOnePushConfigItem(pushConfigItemDto);
    }
}
